home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
program
/
srcbkvt.zip
/
ASC.ZIP
/
HTMLPP.ASC
< prev
next >
Wrap
Text File
|
1996-07-08
|
7KB
|
257 lines
_The Libero Development Environment_
by Pieter Hintjens
Listing One
/^\.\w+\s+([A-Za-z0-9-\._]+)\s+(.*)/
$symbols {$1} = $2;
Listing Two
(a)
-schema=lrschema.pl
After-Init:
(--) Ok -> Have-Line
+ Initialise-Program-Data
+ Open-Main-Document
+ Get-Next-Document-Line
(--) Error ->
+ Terminate-The-Program
(b)
require 'htmlpp1.d'; # Include dialog interpreter
sub initialise_the_program
{
print "htmlpp 1.0 - by Pieter Hintjens\n";
if ($#ARGV == 0) { # Exactly 1 argument in @ARGV[0]?
$main_document = @ARGV [0];
$the_next_event = $ok_event;
} else {
print "syntax: htmlpp <filename>\n";
$the_next_event = $error_event;
}
}
Listing Three
(a)
sub initialise_program_data
{
# These are the preprocessor keywords that we recognise
$keyword {"define"} = $define_event;
$keyword {"include"} = $include_event;
}
(b)
sub open_main_document
{
$document = $main_document;
&open_the_document;
}
sub open_the_document
{
# We use an indirect filehandle, whose name is the document name.
# To read from the file, we use <$document>
if (open ($document, $document)) {
$file_is_open {$document} = 1; # Keep track of open documents
} else {
print "htmlpp E: ($document $.) can't open $document: $!";
&raise_exception ($exception_event);
}
}
Listing Four
open (HANDLE, "somefile.txt");
$line = <HANDLE>;
Listing Five
sub get_next_document_line
{
if ($_ = <$document>) { # Get next line of input
chop; # Remove trailing newline
if (/^$/) { # Blank lines
$the_next_event = $blank_line_event;
}
elsif (/^\.-/) { # Comments
$the_next_event = $comment_event;
}
elsif (/^\./) { # Line starts with a dot
/^\.(\w+)/; # Get word after dot
if (defined ($keyword {$1})) {
$the_next_event = $keyword {$1};
} else {
&syntax_error;
}
} else {
$the_next_event = $body_text_event;
}
} else {
$the_next_event = $finished_event;
}
}
Listing Six
Have-Line:
(--) Body-Text -> Have-Line
+ Expand-Symbols-In-Line
+ Get-Next-Document-Line
(--) Blank-Line -> Have-Line
+ Get-Next-Document-Line
(--) Comment -> Have-Line
+ Get-Next-Document-Line
(--) Define -> Have-Line
+ Expand-Symbols-In-Line
+ Store-Symbol-Definition
+ Get-Next-Document-Line
(--) Include -> Have-Line
+ Expand-Symbols-In-Line
+ Take-Include-File-Name
+ Open-The-Document
+ Get-Next-Document-Line
(--) Finished -> Doc-Unstacked
+ Close-The-Document
+ Unstack-Previous-Document
Listing Seven
(--) Define -> Have-Line
+ Expand-Symbols-In-Line
+ Store-Symbol-Definition
+ Get-Next-Document-Line
Listing Eight
sub store_symbol_definition
{
# Symbol name can consist of letters, digits, -._
# We re-parse the line to extract the symbol name and value:
if (/^\.\w+\s+([A-Za-z0-9-\._]+)\s+(.*)/) {
# Stick name and value into associative array '$symbols'
$symbols {$1} = $2;
} else {
&syntax_error;
}
}
Listing Nine
sub expand_symbols_in_line
{
# Expands symbols in $_ variable
#
# Repeatedly expand symbols like this:
# $(xxx) - value of variable
#
# Note that the entire symbol must be on one line; if the symbol or
# its label is broken over two lines it won't be expanded.
for (;;) {
if (/\$\(([A-Za-z0-9-_\.]+)\)/) {
$_ = $`.&valueof ($1).$';
} else {
last;
}
}
}
# Subroutine returns the value of the specified symbol; it issues a
# warning message and returns 'UNDEF' if the symbol is not defined.
#
sub valueof {
local ($symbol_name) = "@_"; # Argument is symbol name
defined ($symbols {$symbol_name}) && return $symbols {$symbol_name};
print "$_\n";
print "htmlpp E: ($document $.) undefined symbol \"$symbol_name\"\n";
$symbols {$symbol_name} = "UNDEF";
return $symbols {$symbol_name};
}
Listing Ten
(a)
sub syntax_error {
print "$_\n";
print "htmlpp E: ($document $.) syntax error\n";
&raise_exception ($exception_event);
}
(b)
Defaults:
(--) Exception ->
+ Terminate-The-Program
Listing Eleven
(a)
sub take_include_file_name
{
# Get filename after .include
if (/^\.\w+\s+(\S+)/) {
if ($file_is_open {$1}) {
print "$_\n";
print "htmlpp E: ($document $.) $1 is already open";
&raise_exception ($exception_event);
};
# Save current document name and switch to new document
push (@document_stack, $document);
$document = $1;
} else {
&syntax_error;
}
}
(b)
(--) Finished -> Doc-Unstacked
+ Close-The-Document
+ Unstack-Previous-Document
sub close_the_document
{
close ($document);
undef $file_is_open {$document};
}
sub unstack_previous_document
{
$document = pop (@document_stack);
$the_next_event = $document eq ""? $finished_event: $ok_event;
}
Listing Twelve
Doc-Unstacked:
(--) Ok -> Have-Line
+ Get-Next-Document-Line
(--) Finished -> Have-Line
+ Terminate-The-Program
Figure 2:
.include prelude.def
.define version 2.12
.page lrintro.htm=Introduction to Libero
.ignore
<H1>$(TITLE)</H1>
.include contents.def
<H2>Summary</H2>
<UL>
<LI>Libero is a Programmer's Tool and Code Generator.</LI>
<LI>It supports lots of languages.</LI>
<LI>It runs on lots of systems.</LI>
<LI>Current version: $(version).</LI>
</UL>